#!BPY

"""
Name: 'CreateStage'
Blender: 237
Group: 'Export'
Tooltip: 'Create Stage'
"""

from Blender import *

def createStage():
  incAmt = 1.0
  shiftX = 0.0
  shiftZ = 0.0

  sc = Scene.GetCurrent()          # get current scene

  for i in range (0,4):            # Stage Height
    for j in range (0,15):          # Stage Length
      for k in range(0,4):          # Stage Width
        me = Mesh.Primitives.Cube(1.0)   # create a new cube of size 0.5
        ob = Object.New('Mesh')          # create a new mesh-type object
        
        ob.LocY = ob.LocY + (ob.SizeY * k)
        ob.LocX = ob.LocX + shiftX
        ob.LocZ = ob.LocZ + shiftZ
        ob.setName('Cube_'+ str(i) + '_' + str(j) + '_' + str(k))
        
        ob.link(me)
        sc.link(ob)                      # add object to the scene
      shiftX = shiftX + incAmt
    shiftZ = shiftZ - incAmt                 # move the next set of cubes down
    shiftX = 0.0                          # reset x


def placeCamera():
  sc = Scene.GetCurrent()          # get current scene
  ob = Object.New('Camera')

  ob.LocX = -6.044				   # place the camera in space
  ob.LocY = 1.611
  ob.LocZ = 4.776

  ob.RotX = 1.14241				   # rotate it (units in radians)
  ob.RotY = -0.001029
  ob.RotZ = -1.5704

  sc.link(ob)


def placeActor():
  sc = Scene.GetCurrent()          # get current scene
  me = Mesh.Primitives.Cylinder(32,0.75,0.5)  # create a new cylinder
  ob = Object.New('Mesh')          # create a new mesh-type object
        
  ob.LocX = 0.174
  ob.LocY = 1.550
  ob.LocZ = 1.218
  ob.setName('Actor')
        
  ob.link(me)                      # link mesh datablock with object
  sc.link(ob)  


def createLighting():
  sc = Scene.GetCurrent()          # get current scene
  lp = Lamp.New('Lamp','Lamp1')
  ob = Object.New('Lamp')          # create a new mesh-type object
  
  ob.LocX = -2.299
  ob.LocY = 1.784
  ob.LocZ = 4.678

  ob.link(lp)  
  sc.link(ob)


def displayCurrLevel(str):
  sc = Scene.GetCurrent()
  txt = Text3d.New("LevelText")
  
  txt.setText(str)
  txt.setExtrudeDepth(0.15)

  #fnt_obj = Text3d.LoadFont('myfont.ttf')
  #txt.setFont(fnt_obj)

  ob = Object.New('Text')
  ob.link(txt)

  ob.LocX = 0.296
  ob.LocY = 2.892
  ob.LocZ = 2.532

  ob.RotX = 1.566
  ob.RotY = 0.0
  ob.RotZ = -1.5705

  sc.link(ob)
  
def createTextures():
  footex = Texture.New('foo')
  footex.setType('Image')
  img = Image.Load('C:\\Docume~1\\ryan2769\\Desktop\\Blende~1\\metalPlates.jpg')
  footex.image = img

  #mtext = MTex.New('poo')
  #mtext.mapto = ['CUBE']

  mat = Material.New('bar')
  mat.setTexture(0, footex)

	

#createTextures();

createStage();
createLighting();
placeCamera();
placeActor();
displayCurrLevel('Level 1');

Window.RedrawAll()               # update windows